<template>
    <div id="all">
        <i class="el-icon-menu" style="text-align: left">筛选</i>
        <!-- 头部 -->
        <div class="head">
            <label>输入搜索</label>
            <el-input
                v-model="input"
                placeholder="请输入内容"
                style="width: 300px; margin: 0 20px"
            >
            </el-input>
            <el-button type="primary" icon="el-icon-search">筛选</el-button>
            <el-button :plain="true" @click="open2">清空筛选条件</el-button>
        </div>
        <div class="list">
            <i class="el-icon-menu" style="text-align: left">银行列表</i>
            <el-button
                type="primary"
                icon="el-icon-circle-plus-outline"
                @click="go"
                >新增银行</el-button
            >
        </div>
        <!-- 表格 -->
        <el-table
            :data="tableData"
            border
            style="width: 100%; margin-top: 20px"
        >
            <el-table-column fixed prop="bankId" label="银行id" width="200">
            </el-table-column>
            <el-table-column prop="bankName" label="银行名称" width="200">
            </el-table-column>
            <el-table-column  label="银行缩略图" width="200">
                <template slot-scope="scope">
                    <img
                        :src="scope.row.bankimgSrc"
                        v-if="scope.row.bankimgSrc"
                        style="width: 50px"
                    />
                    <span v-else>暂无头像</span>
                </template>
            </el-table-column>
            <el-table-column prop="dayLimit" label="银行当日限额" width="200">
            </el-table-column>
            <el-table-column
                prop="singleLimit"
                label="银行单笔限额"
                width="300"
            >
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="300">
                <template slot-scope="scope">
                    <router-link :to='"/home/editorbank/" + scope.row.bankId'>
                        <el-button
                            size="mini"
                            >编辑</el-button
                        >
                    </router-link>

                    <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)"
                        >删除</el-button
                    >
                </template>
            </el-table-column>
        </el-table>

        <!-- 页码 -->
        <div class="block">
            <el-pagination
                @size-change="handleSizeChange"
                :current-page="currentPage"
                :page-sizes="[5, 8, 10, 15]"
                :page-size="5"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
            >
            </el-pagination>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            input: "",
            tableData: [],
            currentPage: 1,
            total: null,
        };
    },
    created() {
        this.getBank();
    },
    methods: {
        //获取银行
        async getBank() {
            const res = await this.api.bank.getBankData(
                {
                    bankId: 0,
                    bankName: "",
                    bankimgSrc: "",
                    dayLimit: "",
                    singleLimit: "",
                },
                3,
                3
            );
            console.log(res);
            if (res.code == 200) {
                this.tableData = res.data.list;
                this.total = res.data.total;
                this.currentPage = res.data.pageNum;
            } else {
                this.$message({
                    showClose: true,
                    message: "没有数据",
                    type: "error",
                });
            }
        },

        open2() {
            this.$message({
                showClose: true,
                message: "清空成功",
                type: "success",
            });
        },

        //删除银行
        async handleDelete(index, row) {
            const res = await this.api.bank.deleteBank(row.bankId);
            if (res.code == 200) {
                this.$message({
                    showClose: true,
                    message: "删除成功",
                    type: "success",
                });
                this.getallDeletedata();
            } else {
                this.$message({
                    showClose: true,
                    message: "删除失败",
                    type: "error",
                });
            }
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },

        handleClick(row) {
            console.log(row);
        },
        go() {
            this.$router.push({
                path: "/home/addbank",
            });
        },
    },
};
</script>
<style scoped>
.list {
    line-height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.head {
    text-align: left;
    line-height: 50px;
}
.block {
    margin-top: 10px;
    height: 80px;
    text-align: center;
}
.el-main {
    line-height: 20px;
    text-align: left;
}
#all {
    line-height: normal;
    text-align: left;
}
#icon {
    text-align: left;
}
</style>>
    
</style>